<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="../static/jquery-easyui-1.5.5.3/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="../static/jquery-easyui-1.5.5.3/themes/bootstrap/easyui.css"/>
<link rel="stylesheet" type="text/css" href="../static/jquery-easyui-1.5.5.3/themes/icon.css"/>
<script type="text/javascript" src="../static/jquery-easyui-1.5.5.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../static/jquery-easyui-1.5.5.3/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
$(function(){
	$("#beginDate").datebox({
		width: 200,
		editable: false,
		missingMessage:'开始日期必填'
	});
	$("#month").numberbox({
		width: 200,
		missingMessage:'使用期限必填'
	});
	$("#cost").numberbox({
		width: 200,
		missingMessage:'缴纳费用必填'
	});
	
	$("#t_user").datagrid({
		idField:'id',
		title:'租户列表',
		fitColumns:true,
		width:'100%',
		striped:true,
		rownumbers:true,
		url:'list',
		frozenColumns:[
			[
				{
					field:'ck',
					width:50,
					checkbox:true
				}
			]
		],
		columns:[
			[
				{
					field:'id',
					title:'id',
					width:80,
					sortable:true,
					align: 'center'
				},{
					field:'linkman',
					title:'联系人',
					width:80,
					sortable:true,
					align: 'center'
				},{
					field:'phone',
					title:'联系电话',
					width:80,
					sortable:true,
					align: 'center'
				},{
					field:'name',
					title:'租户名称',
					width:80,
					sortable:true,
					align: 'center'
				},{
					field: 'lesseeAdmin',
					title: '租户管理员',
					width: 200,
					align: 'center',
					formatter: function(value){  
						return value.unit;
					}
				}
			]
		],
		pagination:true,
		pageSize:10,
		pageList:[3,5,10,20],
		toolbar: [
			{
				text: '新增授权',
				iconCls: 'icon-add',
				handler: function(){
					var arr = $('#t_user').datagrid('getSelections');
					if(arr.length != 1){
						$.messager.show({
							title: '提示信息',
							msg: '选中一行添加授权！'
						});
					}else{
						$('#mydialog').dialog({
							title: '新增授权'
						});
						$('#myform input').val("");
						$('#myform').form('load', {
							lessee:arr[0].id
						});
						$('#mydialog').dialog('open');
					}
				}
			}
		]
	});

	$('#bin1').click(function(){
		if($('#myform').form('validate')){
			$.ajax({
				type: 'post',
				url: '../accredit/save',
				cache: false,  
				data: $('#myform').serialize(),
				dataType: 'json',
				success: function(){
					$("#mydialog").dialog('close');
					$('#t_user').datagrid('reload');
					$.messager.show({
						title: '提示信息',
						msg: '操作成功！'
					});
				}
			});
		}else{
			$.messager.show({
				title: '提示信息',
				msg: '数据验证不通过，不能保存'
			});
		}
	});
	$('#bin2').click(function(){
		$('#mydialog').dialog('close');
	});
	
});
</script>
</head>
<body>
<div id="ss"> 
		<form id="mysearch" method="post">
				<a href="../accredit/all" type="button">授权管理</a>
		</form>
	</div>
	<table id="t_user"></table>
	
	<div id = "mydialog" title="新增授权" modal="true"  draggable=false class="easyui-dialog" closed=true style="width:300px;">
		<form id="myform" action="invoice/add" method="post">
			<input type="hidden" name = "lessee" value="">
			<table>
				<tr>
					<td>开始日期：</td>
					<td><input type="text" name = "beginDate" id="beginDate" class="easyui-validatebox" required=true value="" ></td>
				</tr>
				<tr>
					<td>使用期限（月）：</td>
					<td><input type="text" name = "month" id="month" class="easyui-validatebox" required=true value="" ></td>
				</tr>
				<tr>
					<td>缴纳费用：</td>
					<td><input type="text" name = "cost" id="cost" class="easyui-validatebox" required=true value="" ></td>
				</tr>
				<tr>
					<td colspan="2" align="center">
						<a id="bin1" class="easyui-linkbutton">确定</a>
						<a id="bin2" class="easyui-linkbutton">关闭</a>
					</td>
				</tr>
			</table>
		</form>
	</div>
</body>
</html>